package com.jobpass.controller;

import com.jobpass.common.data.ResultData;
import com.jobpass.common.model.Practice;
import com.jobpass.common.service.PracticeService;
import com.jobpass.pojo.Practices;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @Author: Qning
 * @Description: 实习上报
 * @Date: 2020/7/22 20:54
 * @PackageName: com.jobpass.controller
 * @ClassName: PracticeController
 */
@Api(tags="实习上报Controller")
@RestController
@RequestMapping("student")
public class PracticeController {
    @Resource
    private PracticeService practiceService;

    /**
     *
     * @Author: Qning
     * @Description: 实习上报
     * @Date: 22:27 2020/7/22
     * @param practices
     * @return: com.jobpass.common.data.ResultData
     */
    @ApiOperation(value="实习上报")
    @PostMapping("savePractice")
    public ResultData savePractice(@RequestBody Practices practices) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Practice practice = new Practice();
        practice.setPay(practices.getPay());
        practice.setDimissionTime(sdf.parse(practices.getDimissionTime()));
        practice.setStudentId(practices.getStudentId());
        practice.setPracticeTime(sdf.parse(practices.getPracticeTime()));
        practice.setEntryTime(sdf.parse(practices.getEntryTime()));
        practice.setSite(practices.getSite());
        practice.setPost(practices.getPost());
        practice.setEnterpriseId(practices.getEnterpriseId());
        int i = practiceService.SavaPractice(practice);
        if (i == 1) {
            return ResultData.success();
        }
        return ResultData.fail();
    }
}
